/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Beans;

import BO.Service;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;
import ws.*;
/**
 *
 * @author Mathias
 */
public class ChatBean {
    private ChatUI chat;
    private int chatId;
    private String message;

    /** Creates a new instance of ChatBean */
    public ChatBean() {
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
    

    public ChatUI getChat() {
        int id = 1;
        ChatUI chat = Service.getChatByID(id);
        
        return chat;
    }

    public void setChat(ChatUI chat) {
        this.chat = chat;
    }

    public int getChatId() {
        return chatId;
    }

    public void setChatId(int chatId) {
        this.chatId = chatId;
    }
    
    public void postMessage(){
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
        UI.UserUI user = ( UI.UserUI )session.getAttribute("User");
        
        Service.createChatMessage(1, message, user.getId() );
        
        message = "";
    }
    
    public List<ChatMessageUI> getMessages(){
        return getChat().getMessages();
    }
    
    
    
    
}
